<template>
    <view :style="{ direction: $t('dir') }" :class="$t('dir') == 'rtl' ? 'rtl' : 'ltr'">
        <navbar :title="$t('settings')"> </navbar>
        <view class="main">
            <!-- 其他 -->
            <view class="ma-md bg-white" style="border-radius: 26rpx; padding: 32rpx 0 150rpx 0">
                <view v-for="(item, index) in otherItems" :key="index" @click="otherItemsClick(item, index)" class="row items-center other-items justify-between my-md" v-show="index == 0 ? token != '' : true">
                    <view style="margin: 0 10px">{{ $t(item.label) }} </view>
                    <view class="row items-center mx-xs">
                        <view v-if="item.value" class="mx-xs" style="color: #9b9b9b">{{ item.value }}</view>
                        <u-icon v-if="item.arrow" :name="'arrow-' + $t('oppo_side')" size="12px" color="#9b9b9b" bold></u-icon>
                    </view>
                </view>
            </view>
        </view>

        <view v-if="token" class="bottom-view">
            <view class="exit-view text-center fs-xl" @click="showExitModal = true">{{ $t('signOut') }}</view>
        </view>

        <!-- 退出APP -->
        <custom-modal :show="showExitModal" @close="showExitModal = false" :content="$t('confirmToSignOut')" @confirm="exitModalConfirm" />

        <!-- 注销账号 -->
        <custom-modal :show="showLogoutModal" @close="showLogoutModal = false" :content="$t('the_account_cannot_be_restored_after_the_cancellation_Do_you_know_the_risks_and_confirm_the_cancellation')" @confirm="_userLogoutaccount" />
    </view>
</template>

<script>
const app = getApp()
const system = uni.getSystemInfoSync()
export default {
    data() {
        return {
            showLogoutModal: false,
            homePopupRecommended: true,
            otherItems: [
                {
                    label: 'shezhemima',
                    arrow: true,
                    path: '/pages/settings/forget-pwd',
                },
                {
                    label: 'clearTheCache',
                    value: '0.00B',
                },
                // {
                //     label: 'checkForNewVersions',
                //     value: 'v' + system.appVersion,
                // },
                // {
                //     label: 'close_an_account',
                //     arrow: true,
                // },
            ],
            showExitModal: false,
            token: '',
            userInfo: {
                nickname: '',
                avatar: '',
                id: 0,
                buyCount: 0,
                follow: 0,
                fans: 0,
                test: 1,
                model_type: '',
                // 申请 landlord房东broker经纪 store门店  company公司 partner合伙
            },
        }
    },
    created() {},
    mounted() {},
    onReady() {},
    onLoad(e) {},
    onShow() {
        this.userInfo = uni.getStorageSync('user')
        this.token = uni.getStorageSync('token')
    },
    methods: {
        goToManageIndex() {
            if (this.userInfo.model_type == 'landlord' || this.userInfo.model_type == 'broker') {
                this.$tools.goTo('/cooperate/pages/resource/index')
            } else this.$tools.goTo('/cooperate/pages/manage/index')
        },
        otherItemsClick(item, index) {
            if (item.path) {
                uni.navigateTo({
                    url: item.path,
                })
            }
            // 清除缓存成功
            else if (index == 1) {
                let that = this
                uni.clearStorage({
                    success: function () {
                        uni.showToast({
                            title: '',
                            duration: 2000,
                            icon: 'success',
                        })
                        console.log('清除缓存成功')
                    },
                    fail: function (err) {
                        console.log('清除缓存失败', err)
                    },
                })
            } else if (index == 3) {
                this.showLogoutModal = true
            }
        },
   
        _userLogoutaccount() {
            this.$uniapi.userLogoutaccount().then((res) => {
                if (res.code == '00000') {
                    let that = this
                    uni.showToast({
                        title: '',
                        duration: 2000,
                        icon: 'success',
                    })
                    uni.clearStorage({
                        success: function () {
                            that.exitModalConfirm()
                            console.log('清除缓存成功')
                        },
                        fail: function (err) {
                            console.log('清除缓存失败', err)
                        },
                    })
                }
            })
        },
        exitModalConfirm() {
            uni.removeStorageSync('uid')
            uni.removeStorageSync('token')
            uni.removeStorageSync('user')
            this.showExitModal = false
            this.token = ''
            getApp().globalData.isConnectedWebsocket = false
            // uni.closeSocket()
            uni.showToast({
                title: this.$t('logoutSuccessful'),
                icon: 'none',
            })
            setTimeout(() => {
                uni.reLaunch({ url: '/pages/my/index' })
            }, 500)
        },
    },
}
</script>
<style scoped lang="scss">
.other-items {
    padding: 40rpx 0;
    border-bottom: 1rpx solid #f3f3f3;
    margin: 0 36rpx;
}

// .other-items:last-child {
//     border: none;
// }

.bottom-view {
    position: fixed;
    bottom: 60px;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.exit-view {
    background: var(--app-color);
    color: white;
    width: 60%;
    padding: 16rpx;
    border-radius: 60rpx;
}
</style>